﻿using System.Collections.Generic;

namespace EduFormManager.Models
{
    public class Credentials : Entity
    {
        public enum Type
        {
            Admin = 1,
            Ministry = 2,
            Municipality = 3,
            Edu = 4
        }
        private Municipality m_munit;
        private EduOrg m_edu;
        private int m_loginType;

        public virtual string Login { get; set; }
        public virtual string Password { get; set; }
        public virtual int ReferenceID { get; set; }

        public virtual ISet<Query> FormQueries { get; set; } 

        public virtual string Name
        {
            get
            {
                switch (this.LoginType)
                {
                    case Type.Edu:
                        return m_edu.ShortName;
                    case Type.Municipality:
                        return m_munit.Name;
                    case Type.Admin:
                        return "Администратор";
                    case Type.Ministry:
                        return "Министерство";
                    default:
                        return "";
                }
            }
        }
        public virtual EduOrg EduOrg
        {
            get
            {
                return m_edu;
            }
            set
            {
                m_edu = value;
                m_munit = null;
            }
        }
        public virtual Municipality Municipality
        {
            get
            {
                return m_munit;
            }
            set
            {
                m_munit = value;
                m_edu = null;
            }
        }
        public virtual Type LoginType
        {
            get
            {
                return (Type)m_loginType;
            }
            set
            {
                m_loginType = (int)value;
            }
        }
        public virtual bool IsAdmin
        {
            get 
            { 
                return (Type)m_loginType == Type.Admin; 
            }
        }
        public virtual bool IsEdu
        {
            get 
            {
                return (Type)m_loginType == Type.Edu; 
            }
        }
        public virtual bool IsMinistry
        {
            get 
            {
                return (Type)m_loginType == Type.Ministry; 
            }
        }
        public virtual bool IsMunicipality
        {
            get
            {
                return (Type)m_loginType == Type.Municipality;
            }
        }
    }
}
